<template>
  <div>
    <van-picker
      title="标题"
      show-toolbar
      :columns="columns"
      :default-index="index"
      @confirm="onConfirm"
      @cancel="onCancel"
      @change="onChange"
    />
  </div>
</template>

<script>
import { name } from '@/api/info.js'
export default {
  name: 'sex',
  props: ['sex'],
  data () {
    return {
      index: this.sex,
      columns: ['男', '女']
    }
  },
  methods: {
    async onConfirm () {
      this.$toast.loading({
        message: '加载中...',
        duration: 0, // 持续展示 toast
        forbidClick: true
      })
      try {
        await name({ gender: this.index })
        this.$toast.success('修改成功')
        this.$emit('setData')
      } catch (error) {
        this.$toast.fail('修改失败')
      }
    },
    onChange (a, b, c) {
      this.index = c
    },
    onCancel () {
      this.$emit('setShow')
    }
  }
}
</script>

<style>
</style>
